<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="my" uri="http://amani.com/function-taglib"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>VIP预约</title>
<%@ include file="../shared/common_header.jsp"%>

</head>
<body>
	<section id="orders" class='step4' > 
	<div class="content"> 
			<ul class="table-view">
				<li class="table-view-cell">
					<span class="table-view-cell-colunm-left">预约项目类型</span>
					<span class="table-view-cell-colunm-right">${my:displayOrderFactProjectName(ordersFactProject)}</span>
				</li>
				<c:if test="${fn:length(projectname)>0  }">
				<li class="table-view-cell">
					<span class="table-view-cell-colunm-left">预约项目</span>
					<span class="table-view-cell-colunm-right">${projectname}</span>
				</li>
				</c:if>
				<li class="table-view-cell">
					<span class="table-view-cell-colunm-left">预约时间</span>
					<span class="table-view-cell-colunm-right" id="orderDate"></span>
				</li> 
				<li class="table-view-cell">
					<span class="table-view-cell-colunm-left">理发师</span>
					<span class="table-view-cell-colunm-right">${staff.staffname }</span>
				</li> 
				<li class="table-view-cell">
					<span class="table-view-cell-colunm-left">联系电话</span>
					<span class="table-view-cell-colunm-right">${staff.mobilephone }</span>
				</li> 
				<li class="table-view-cell">
					<span class="table-view-cell-colunm-left">服务地址</span>
					<span class="table-view-cell-colunm-right">${staff.compaddress }</span>
				</li> 
			</ul>

		</div>
		<div class="bar bar-standard bar-footer"> 
		<c:if test="${sourceType !='Orders'}">   
			<div class='acount'>
				<div>合计：<span>￥<span class='count-price'>${price}</span></span></div> 
			</div>
			<div class='commit'> 
				<span id="commitOrder" class="btn btn-commit">确认付款</span>
			</div>
		</c:if>
		<c:if test="${sourceType =='Orders'}">   
			<div class='commit'> 
				<span id="commitOrder" class="btn btn-commit">确认预约</span>
			</div>
		</c:if>
			
		</div>
	</section>
	<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	<script type="text/javascript">
		var orderDate = null;
		$(function() {
			 wx.config({
			        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
			        appId: '${appId}', // 必填，公众号的唯一标识
			        timestamp:"${jsapi_timestamp}", // 必填，生成签名的时间戳
			        nonceStr: '${jsapi_nonceStr}', // 必填，生成签名的随机串
			        signature: '${jsapi_signature}', // 必填，签名，见附录1
			        jsApiList: ['chooseWXPay', 'hideOptionMenu'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
			    });
			 
			(function(){ 
				var orderDate=parseInt("${orderDate}");
				orderDate=new Date(orderDate);
				var month=orderDate.getMonth()<9?"0"+(orderDate.getMonth()+1):(orderDate.getMonth()+1);
				var date1=orderDate.getDate()<10?"0"+(orderDate.getDate()):(orderDate.getDate());
				var hour = orderDate.getHours();
				var minutes = orderDate.getMinutes();
				orderDate = orderDate.getFullYear()+'-'+month+'-'+date1 +" "+hour+":"+minutes;
			    $("#orderDate").text(orderDate);
			})();
			
			$("#commitOrder").bind("click", function(e) { 
				var sourceType="${sourceType}"; 
				var cardid="${cardid}";
				var projectno='${projectno}';
				if(sourceType=="Orders"){
					projectno="${ordersFactProject}";
				}
				var projectname='${projectname}';
				if(sourceType=="Orders"){
					projectname="${my:displayOrderFactProjectName(ordersFactProject)}";
				} 
				var commitData={
								"cardno":"${cardno}",
								"mobile":"${staff.mobilephone }",
								"projectno":projectno,
								"projectname":projectname,
								"compid":"${companyno}",
								"orderDate":"${orderDate}",
								"compname":"${compname}",
								"staffno":"${staff.staffno}",
								"manageno":"",
								"staffname":"${staff.staffname }",
								"sourceType":sourceType,
								"price":"${price}",
								"orderid":"${orderid }",
								"ispz":"0",};
				$("#commitOrder").attr("disabled",true);
				//提交订单
				$.ajax({
					 type: "post",
			         url: "${ROOT_PATH}Orders/CommitOrder",
			         data: commitData,
			         dataType: "json",
			         error: function(XMLHttpRequest, textStatus, errorThrown) {
	                        alert(XMLHttpRequest.status);
	                        alert(XMLHttpRequest.readyState);
	                        alert(textStatus);
	                    },
			         success: function (o) { 
			        	 if(!o.isSuccessed){
			        		 alert(o.exceptionCode); 
			        	 }
			         	if(o.isSuccessed && sourceType!='Orders'){
				        	 $("#commitOrder").attr("disabled",false);  
				        	 
				        	 /* var openids=["orCjajnADjE1mhSo3K5gHzODwdeI",""];
				        	 var contiansId=false;
				        	 for(var i=0;i<openids;i++){
				        		 if(openids[i]=="${openid }"){
				        			 contiansId=true;
				        			 break;
				        		 }
				        	 }
				        	 if(!contiansId){
				        		 alert("内测期间，未受邀请用户暂时无法使用，请您见谅！"); 
				        		 return;
				        	 } */
			         		//调用微信支付接口 
			         		var payData=o.payJsonData;
			         		payData.success=function (res) { 
			         			if(res.errMsg='chooseWxPay:ok'){
				         			$.ajax({
										 type: "post",
								         url: "${ROOT_PATH}/SendCard",
								         data: {cardId:'${cardid}',orderNo:'${orderid}'},
								         dataType: "json",
								         success: function (o) {  
								        	var cardCode=o.cardCode;
								        	var cardInfo={cardId: o.cardId, cardExt: JSON.stringify(o.cardExt)};
								        	var addCardInfo={cardList:[],success: function (res) {  
					                           if(res.errMsg=='addCard:ok'){
					                        		window.location.href="${ROOT_PATH}Orders/Success?status=20&cardCode="+res.cardList[0].cardExt+"&cardId=${cardid}&orderDate="+orderDate+"&staffno=${staff.staffno}&ordersProject${my:displayOrderFactProjectName(ordersFactProject)}";
					                           }else{
					                        	   window.location.href="${ROOT_PATH}Orders/Success?status=21&cardCode="+cardCode+"&cardId=${cardid}";
					                           } 
					                        }};
								        	addCardInfo.cardList.push(cardInfo);
							                wx.addCard(addCardInfo); 
								         }
									});
			         			}
						    };
			         		wx.chooseWXPay(payData);     
			         	} else{ 
			         		if(o.isSuccessed ){
		         				window.location.href="${ROOT_PATH}Orders/Success?status=1";
			         		}
			         	}
			         }
				});
			});
		});
	</script>
</body>
</html>